setwd("")

#load packages
library(tidyverse)
library(readxl)
library(wnominate)
library(oc)
library(patchwork)
library(stargazer)
library(car)

#load data
EP5_RCV_Internet <- read_csv("EP5_RCV_Internet.csv")
EP6_RCV_Internet <- read_csv("EP6_RCV_Internet.csv")
EP7_RCV_Internet <- read_csv("EP7_RCV_Internet.csv")

EP5_MEPs <- read_csv("EP5_MEPs.csv")
EP6_MEPs <- read_csv("EP6_MEPs.csv")
EP7_MEPs <- read_csv("EP7_MEPs.csv")

#OC (Optimal classification) scaling

##EP5
set.seed(123)

RCV_EP5 <- rollcall(data=EP5_RCV_Internet[,6:ncol(EP5_RCV_Internet)],
                    yea=1,
                    nay=2,
                    missing=c(0,3,4),
                    notInLegis = 5,
                    legis.names = EP5_RCV_Internet$name,
                    vote.names = colnames(EP5_RCV_Internet[,6:ncol(EP5_RCV_Internet)]),
                    legis.data=EP5_RCV_Internet[1:5],
                    vote.data = NULL)

oc_EP5 <- oc(RCV_EP5, polarity = c("BORGHEZIO Mario", "BORGHEZIO Mario"))

EP5_MEPs$oc_dim1 <- oc_EP5$legislators$coord1D
EP5_MEPs$oc_dim2 <- oc_EP5$legislators$coord2D

###plot MEP ideal points
EP5_oc_plot <- ggplot(EP5_MEPs, aes(x=oc_dim1, y=oc_dim2)) +
  geom_point(aes(color = epg, shape=epg),
             size= 3) +
  scale_color_manual(values = c("ELDR" = "#FF00CCFF", "EDD" = "#00FFFFFF", "EPP" = "#0000CCFF", "EUL/NGL" = "#358000FF", "G/EFA" = "#00FF00FF", "PSE" = "#FF0000FF", "UEN" = "#FF9900FF","na"="#CCCCCCFF")) +
  scale_shape_manual(values = c("ELDR" = "A", "EDD" = "F", "EPP" = "E", "EUL/NGL" = "L", "G/EFA" = "G", "PSE" = "S", "UEN" = "N", "na"="I")) +
  coord_fixed() +
  xlab('liberal / authoritarian') +
  ylab('pro / anti EU') +
  xlim(-1, 1) +
  ylim(-1, 1) +
  labs(title = 'EP5 Internet Policy')

EP5_oc_plot

###plot national party ideal points 
EP5_Parties <- EP5_MEPs %>% group_by(ches_id) %>% dplyr::summarize_at(vars(oc_dim1, oc_dim2), mean, na.rm=TRUE)
EP5_Parties <- EP5_Parties %>% drop_na(ches_id) %>% 
  rename(party_oc_dim1=oc_dim1) %>% 
  rename(party_oc_dim2=oc_dim2)

EP5_MEPs <- EP5_MEPs %>% full_join(EP5_Parties, by="ches_id")

EP5_OC_Party_Plot <- ggplot(EP5_MEPs, aes(x=party_oc_dim1, y=party_oc_dim2)) +
  geom_point(aes(color = epg, shape = epg),
             size= 3) +
  scale_color_manual(values = c("ELDR" = "#FF00CCFF", "EDD" = "#00FFFFFF", "EPP" = "#0000CCFF", "EUL/NGL" = "#358000FF", "G/EFA" = "#00FF00FF", "PSE" = "#FF0000FF", "UEN" = "#FF9900FF","na"="#CCCCCCFF")) +
  scale_shape_manual(values = c("ELDR" = "A", "EDD" = "F", "EPP" = "E", "EUL/NGL" = "L", "G/EFA" = "G", "PSE" = "S", "UEN" = "N", "na"="I")) +
  coord_fixed() +
  xlab('liberal / authoritarian') +
  ylab('pro / anti EU') +
  xlim(-1, 1) +
  ylim(-1, 1) +
  labs(title = 'EP5 Internet Policy (National Parties)')
EP5_OC_Party_Plot


##EP6
set.seed(456)

RCV_EP6 <- rollcall(data=EP6_RCV_Internet[,9:ncol(EP6_RCV_Internet)], 
                    yea=1, 
                    nay=2, 
                    missing=c(0,3,4), 
                    notInLegis=5, 
                    legis.names = EP6_RCV_Internet$mep_id,
                    vote.names = colnames(EP6_RCV_Internet[,9:ncol(EP6_RCV_Internet)]),
                    legis.data = EP6_RCV_Internet[,1:8],
                    vote.data = NULL,
                    desc = NULL)

oc_EP6 <- oc(RCV_EP6, polarity = c(625, 625))

EP6_MEPs$oc_dim1 <- oc_EP6$legislators$coord1D
EP6_MEPs$oc_dim2 <- oc_EP6$legislators$coord2D

###plotMEP ideal points 
EP6_oc_plot <- ggplot(EP6_MEPs, aes(x=oc_dim1, y=oc_dim2)) +
  geom_point(aes(color = epg_name, shape = epg_name),
             size= 3) +
  scale_color_manual(values = c("ALDE" = "#FF00CCFF", "IND/DEM" = "#00FFFFFF", "EPP-ED" = "#0000CCFF", "EUL/NGL" = "#358000FF", "G/EFA" = "#00FF00FF", "SOC" = "#FF0000FF", "UEN" = "#FF9900FF","na"="#CCCCCCFF")) +
  scale_shape_manual(values = c("ALDE" = "A", "IND/DEM" = "F", "EPP-ED" = "E", "EUL/NGL" = "L", "G/EFA" = "G", "SOC" = "S", "UEN" = "N", "na"="I")) +
  coord_fixed() +
  xlab('liberal / authoritarian') +
  ylab('pro / anti EU') +
  xlim(-1, 1) +
  ylim(-1, 1) +
  labs(title = 'EP6 Internet Policy')

EP6_oc_plot

###plot national party ideal points 
EP6_Parties <- EP6_MEPs %>% group_by(ches_id) %>% 
  dplyr::summarize_at(vars(oc_dim1, oc_dim2), mean, na.rm=TRUE)
EP6_Parties <- EP6_Parties %>% drop_na(ches_id) %>% 
  rename(party_oc_dim1=oc_dim1) %>% 
  rename(party_oc_dim2=oc_dim2) 

EP6_MEPs <- EP6_MEPs %>% full_join(EP6_Parties, by="ches_id")

EP6_OC_Party_Plot <- ggplot(EP6_MEPs, aes(x=party_oc_dim1, y=party_oc_dim2)) +
  geom_point(aes(color = epg_name, shape = epg_name),
             size= 3) +
  scale_color_manual(values = c("ALDE" = "#FF00CCFF", "IND/DEM" = "#00FFFFFF", "EPP-ED" = "#0000CCFF", "EUL/NGL" = "#358000FF", "G/EFA" = "#00FF00FF", "SOC" = "#FF0000FF", "UEN" = "#FF9900FF","na"="#CCCCCCFF")) +
  scale_shape_manual(values = c("ALDE" = "A", "IND/DEM" = "F", "EPP-ED" = "E", "EUL/NGL" = "L", "G/EFA" = "G", "SOC" = "S", "UEN" = "N", "na"="I")) +
  coord_fixed() +
  xlab('liberal / authoritarian') +
  ylab('pro / anti EU') +
  xlim(-1, 1) +
  ylim(-1, 1) +
  labs(title = 'EP6 Internet Policy (National Parties)')

EP6_OC_Party_Plot


##EP7
set.seed(567)

RCV_EP7 <- rollcall(data=EP7_RCV_Internet[,6:ncol(EP7_RCV_Internet)], 
                    yea=1, 
                    nay=2, 
                    missing=c(3,4,5), 
                    notInLegis=0, 
                    legis.names = EP7_RCV_Internet$mep_id,
                    vote.names = colnames(EP7_RCV_Internet[,6:ncol(EP7_RCV_Internet)]),
                    legis.data = EP7_RCV_Internet[,1:5],
                    vote.data = NULL,
                    desc = NULL)

oc_EP7 <- oc(RCV_EP7, polarity = c(72, 72))

EP7_MEPs$oc_dim1 <- oc_EP7$legislators$coord1D
EP7_MEPs$oc_dim2 <- oc_EP7$legislators$coord2D

EP7_MEPs$oc_dim2_rotated <- EP7_MEPs$oc_dim2 * (-1)  #rotating 2nd DIM

##plot MEP ideal points
EP7_oc_plot_rotated <- ggplot(EP7_MEPs, aes(x=oc_dim1, y=oc_dim2_rotated)) +
  geom_point(aes(color = epg, shape = epg),
             size= 3) +
  scale_color_manual(values = c("ALDE" = "#FF00CCFF", "ECR" = "#9900CCFF", "EFDD" = "#00FFFFFF", "EPP" = "#0000CCFF", "EUL/NGL" = "#358000FF", "G/EFA" = "#00FF00FF", "S&D" = "#FF0000FF", "na"="#CCCCCCFF")) +
  scale_shape_manual(values = c("ALDE" = "A", "ECR" = "C", "EFDD" = "F", "EPP" = "E", "EUL/NGL" = "L", "G/EFA" = "G", "S&D" = "S", "na"="I")) +
  coord_fixed() +
  xlab('liberal / authoritarian') +
  ylab('pro / anti EU') +
  xlim(-1, 1) +
  ylim(-1, 1) +
  labs(title = 'EP7 Internet Policy')

EP7_oc_plot_rotated

### plot national party ideal points
EP7_Parties <- EP7_MEPs %>% group_by(ches_id) %>% dplyr::summarize_at(vars(oc_dim1, oc_dim2, oc_dim2_rotated), mean, na.rm=TRUE)
EP7_Parties <- EP7_Parties %>% drop_na(ches_id) %>% 
  rename(party_oc_dim1=oc_dim1) %>% 
  rename(party_oc_dim2=oc_dim2) %>% 
  rename(party_oc_dim2_rotated=oc_dim2_rotated)

EP7_MEPs <- EP7_MEPs %>% full_join(EP7_Parties, by="ches_id")

EP7_oc_party_plot_rotated <- ggplot(EP7_MEPs, aes(x=party_oc_dim1, y=party_oc_dim2_rotated)) +
  geom_point(aes(color = epg, shape = epg),
             size= 3) +
  scale_color_manual(values = c("ALDE" = "#FF00CCFF", "ECR" = "#9900CCFF", "EFDD" = "#00FFFFFF", "EPP" = "#0000CCFF", "EUL/NGL" = "#358000FF", "G/EFA" = "#00FF00FF", "S&D" = "#FF0000FF", "na"="#CCCCCCFF")) +
  scale_shape_manual(values = c("ALDE" = "A", "ECR" = "C", "EFDD" = "F", "EPP" = "E", "EUL/NGL" = "L", "G/EFA" = "G", "S&D" = "S", "na"="I")) +
  coord_fixed() +
  xlab('liberal / authoritarian') +
  ylab('pro / anti EU') +
  xlim(-1, 1) +
  ylim(-1, 1) +
  labs(title = 'EP7 Internet Policy (National Parties)')

EP7_oc_party_plot_rotated


##Figure 1
F1 <- EP5_oc_plot + EP6_oc_plot + EP7_oc_plot_rotated + 
  EP5_OC_Party_Plot+ EP6_OC_Party_Plot + EP7_oc_party_plot_rotated +
  plot_layout(ncol=3)

ggsave("F1.jpeg", F1, width = 33.1, height = 16.1, units = "cm", dpi = 300)



####
#Regression Analysis (Tables 2-4)

##EP5 regression models

###data preparation
EP5_Parties <- EP5_MEPs %>% 
  dplyr::select(party_short, ches_id, member_state, epg, lrecon, galtan, position, govt, 
                28:ncol(EP5_MEPs)) %>% 
  group_by(party_short, ches_id, epg) %>% 
  summarise_each(funs(first(.)))

EP5_Parties <- EP5_Parties %>% 
  mutate(ingovt = case_when((govt == "in government") ~ as.numeric(1), TRUE ~ as.numeric(0))) %>%
  mutate(region = case_when(member_state == "A" ~ "north", 
                            member_state == "B" ~ "north",
                            member_state == "K" ~ "north", 
                            member_state == "O" ~ "north", 
                            member_state == "D" ~ "north", 
                            member_state == "R" ~ "north", 
                            member_state == "L" ~ "north", 
                            member_state == "N" ~ "north", 
                            member_state == "S" ~ "north", 
                            member_state == "U" ~ "north", 
                            TRUE ~ member_state)) %>% 
  mutate(region = case_when(member_state == "F" ~ "south",
                            member_state == "G" ~ "south", 
                            member_state == "I" ~  "south", 
                            member_state == "M" ~  "south", 
                            member_state == "P" ~ "south", 
                            member_state == "E" ~ "south", 
                            TRUE ~ region)) %>% 
  mutate(north = case_when(region == "north" ~ as.numeric(1), TRUE ~ as.numeric(0))) %>% 
  mutate(south = case_when(region == "south" ~ as.numeric(1), TRUE ~ as.numeric(0))) 


EP5_Parties <- EP5_Parties %>% drop_na()  #drop rows with missing values

###Model1: lrecon
EP5_model1_dim1 <- lm(party_oc_dim1 ~ lrecon + position + ingovt + north, data = EP5_Parties)
EP5_model1_dim2 <- lm(party_oc_dim2 ~ lrecon + position + ingovt + north, data = EP5_Parties)

###Model2: galtan
EP5_model2_dim1 <- lm(party_oc_dim1 ~ galtan + position + ingovt + north, data = EP5_Parties)
EP5_model2_dim2 <- lm(party_oc_dim2 ~ galtan + position + ingovt + north, data = EP5_Parties)

###Model3: lrecon + galtan
EP5_model3_dim1 <- lm(party_oc_dim1 ~ lrecon + galtan + position + ingovt + north, data = EP5_Parties)
EP5_model3_dim2 <- lm(party_oc_dim2 ~ lrecon + galtan + position + ingovt + north, data = EP5_Parties)

###Table 2
EP5_output <- stargazer(EP5_model1_dim1, EP5_model1_dim2, EP5_model2_dim1, EP5_model2_dim2, EP5_model3_dim1, EP5_model3_dim2,
                        type             = "html",
                        out = "T2.html", 
                        title            = "EP5 National Party Delegations (Internet Policy RCVs)",
                        covariate.labels = c("Economic Left-Right", "GAL-TAN", "EU Integration", "In National Government", "Northern MS"),
                        dep.var.caption  = "OC Score",
                        dep.var.labels   = c("Model1, Dim1", "Model1, Dim2", "Model2, Dim1", " Model2, Dim2", "Model3, Dim1", " Model3, Dim2"),
                        model.numbers    = FALSE)

##EP6 regression models

###prepare data
EP6_Parties <- EP6_MEPs %>% 
  dplyr::select(party_short, ches_id, country_name, epg_name, lrecon, galtan, position, deregulation, civlib_laworder, civlib_salience, govt, 
                27:ncol(EP6_MEPs)) %>% 
  group_by(party_short, ches_id, country_name, epg_name) %>% 
  summarise_each(funs(first(.)))

EP6_Parties <- EP6_Parties %>% 
  mutate(ingovt = case_when((govt == "in government") ~ as.numeric(1), TRUE ~ as.numeric(0))) %>%
  mutate(region = case_when(country_name == "Austria" ~ "north", 
                            country_name == "Belgium" ~ "north",
                            country_name == "Denmark" ~ "north", 
                            country_name == "Finland" ~ "north", 
                            country_name == "Germany" ~ "north", 
                            country_name == "Ireland" ~ "north", 
                            country_name == "Luxemburg" ~ "north", 
                            country_name == "Netherlands" ~ "north", 
                            country_name == "Sweden" ~ "north", 
                            country_name == "UK" ~ "north", 
                            TRUE ~ country_name)) %>% 
  mutate(region = case_when(country_name == "Cyprus" ~ "south", 
                            country_name == "France" ~ "south",
                            country_name == "Greece" ~ "south", 
                            country_name == "Italy" ~  "south", 
                            country_name == "Malta" ~  "south", 
                            country_name == "Portugal" ~ "south", 
                            country_name == "Spain" ~ "south", 
                            TRUE ~ region)) %>% 
  mutate(region = case_when(country_name == "Bulgaria"       ~ "east", 
                            country_name == "Czech Republic" ~ "east",
                            country_name == "Estonia"        ~ "east", 
                            country_name == "Hungary"        ~ "east", 
                            country_name == "Latvia"         ~ "east", 
                            country_name == "Lithuania"      ~ "east", 
                            country_name == "Poland"         ~ "east", 
                            country_name == "Romania"        ~ "east", 
                            country_name == "Slovakia"       ~ "east", 
                            country_name == "Slovenia"       ~ "east", 
                            TRUE ~ region)) %>% 
  mutate(north = case_when(region == "north" ~ as.numeric(1), TRUE ~ as.numeric(0))) %>% 
  mutate(south = case_when(region == "south" ~ as.numeric(1), TRUE ~ as.numeric(0))) %>% 
  mutate(east = case_when(region == "east" ~ as.numeric(1), TRUE ~ as.numeric(0))) 

EP6_Parties <- EP6_Parties %>% drop_na()  #drop rows with missing values

###Model1: lrecon
EP6_model1_dim1 <- lm(party_oc_dim1 ~ lrecon + position + ingovt + north + east, data = EP6_Parties)
EP6_model1_dim2 <- lm(party_oc_dim2 ~ lrecon + position + ingovt + north + east, data = EP6_Parties)

###Model2: galtan
EP6_model2_dim1 <- lm(party_oc_dim1 ~ galtan + position + ingovt + north + east, data = EP6_Parties)
EP6_model2_dim2 <- lm(party_oc_dim2 ~ galtan + position + ingovt + north + east, data = EP6_Parties)

###Model3: lrecon + galtan
EP6_model3_dim1 <- lm(party_oc_dim1 ~ lrecon + galtan + position + ingovt + north + east, data = EP6_Parties)
EP6_model3_dim2 <- lm(party_oc_dim2 ~ lrecon + galtan + position + ingovt + north + east, data = EP6_Parties)

###Model 4: deregulation 
EP6_model4_dim1 <- lm(party_oc_dim1 ~ deregulation + position + ingovt + north + east, data = EP6_Parties)
EP6_model4_dim2 <- lm(party_oc_dim2 ~ deregulation + position + ingovt + north + east, data = EP6_Parties)

###Model 5: civlib_laworder
EP6_model5_dim1 <- lm(party_oc_dim1 ~ civlib_laworder + position + ingovt + north + east, data = EP6_Parties)
EP6_model5_dim2 <- lm(party_oc_dim2 ~ civlib_laworder + position + ingovt + north + east, data = EP6_Parties)

###Model 6: deregulation + civlib_laworder
EP6_model6_dim1 <- lm(party_oc_dim1 ~ deregulation + civlib_laworder + position + ingovt + north + east, data = EP6_Parties)
EP6_model6_dim2 <- lm(party_oc_dim2 ~ deregulation + civlib_laworder + position + ingovt + north + east, data = EP6_Parties)


###Table 2
EP6_output <- stargazer(EP6_model1_dim1, EP6_model1_dim2, EP6_model2_dim1, EP6_model2_dim2, EP6_model3_dim1, EP6_model3_dim2, EP6_model4_dim1, EP6_model4_dim2, EP6_model5_dim1, EP6_model5_dim2, EP6_model6_dim1, EP6_model6_dim2,
                        type             = "html",
                        out = "T3.html", 
                        title            = "EP6 National Party Delegations (Internet Policy RCVs)",
                        covariate.labels = c("Economic Left-Right", "GAL-TAN", "Deregulation", "Civil Liberties-Law&Order", "EU Integration", "In National Government", "Northern MS", "Eastern MS"),
                        dep.var.caption  = "OC Score",
                        dep.var.labels   = c("Model1, Dim1", "Model1, Dim2", "Model2, Dim1", "Model2, Dim2", "Model3, Dim1", "Model3, Dim2", "Model4, Dim1", "Model4, Dim2", "Model5, Dim1", "Model5, Dim2", "Model6, Dim1", "Model6, Dim2"),
                        model.numbers    = FALSE)


## EP7 regression models

###data preparation
EP7_Parties <- EP7_MEPs %>% 
  dplyr::select(party_short, ches_id, country, epg, lrecon, galtan, position, deregulation, civlib_laworder, civlib_salience, govt, 
                27:ncol(EP7_MEPs)) %>% 
  group_by(party_short, ches_id, epg) %>% 
  summarise_each(funs(first(.)))

EP7_Parties <- EP7_Parties %>% 
  mutate(ingovt = case_when((govt == "in government") ~ as.numeric(1), TRUE ~ as.numeric(0))) %>% 
  mutate(region = case_when(country == "Austria" ~ "north", 
                            country == "Belgium" ~ "north",
                            country == "Denmark" ~ "north", 
                            country == "Finland" ~ "north", 
                            country == "Germany" ~ "north", 
                            country == "Ireland" ~ "north", 
                            country == "Luxembourg" ~ "north", 
                            country == "Netherlands" ~ "north", 
                            country == "Sweden" ~ "north", 
                            country == "United Kingdom" ~ "north", 
                            TRUE ~ country)) %>% 
  mutate(region = case_when(country == "Cyprus" ~ "south", 
                            country == "France" ~ "south",
                            country == "Greece" ~ "south", 
                            country == "Italy" ~  "south", 
                            country == "Malta" ~  "south", 
                            country == "Portugal" ~ "south", 
                            country == "Spain" ~ "south", 
                            TRUE ~ region)) %>% 
  mutate(region = case_when(country == "Bulgaria"       ~ "east",
                            country == "Croatia"       ~ "east",
                            country == "Czech Republic" ~ "east",
                            country == "Estonia"        ~ "east", 
                            country == "Hungary"        ~ "east", 
                            country == "Latvia"         ~ "east", 
                            country == "Lithuania"      ~ "east", 
                            country == "Poland"         ~ "east", 
                            country == "Romania"        ~ "east", 
                            country == "Slovakia"       ~ "east", 
                            country == "Slovenia"       ~ "east", 
                            TRUE ~ region)) %>% 
  mutate(north = case_when(region == "north" ~ as.numeric(1), TRUE ~ as.numeric(0))) %>% 
  mutate(south = case_when(region == "south" ~ as.numeric(1), TRUE ~ as.numeric(0))) %>% 
  mutate(east = case_when(region == "east" ~ as.numeric(1), TRUE ~ as.numeric(0))) 

EP7_Parties <- EP7_Parties %>% drop_na()  ##drop rows with missing values

###Model1: lrecon
EP7_model1_dim1 <- lm(party_oc_dim1 ~ lrecon + position + ingovt + north + east, data = EP7_Parties)
EP7_model1_dim2 <- lm(party_oc_dim2 ~ lrecon + position + ingovt + north + east, data = EP7_Parties)

###Model2: galtan
EP7_model2_dim1 <- lm(party_oc_dim1 ~ galtan + position + ingovt + north + east, data = EP7_Parties)
EP7_model2_dim2 <- lm(party_oc_dim2 ~ galtan + position + ingovt + north + east, data = EP7_Parties)

###Model3: lrecon + galtan
EP7_model3_dim1 <- lm(party_oc_dim1 ~ lrecon + galtan + position + ingovt + north + east, data = EP7_Parties)
EP7_model3_dim2 <- lm(party_oc_dim2 ~ lrecon + galtan + position + ingovt + north + east, data = EP7_Parties)

###Model 4: deregulation 
EP7_model4_dim1 <- lm(party_oc_dim1 ~ deregulation + position + ingovt + north + east, data = EP7_Parties)
EP7_model4_dim2 <- lm(party_oc_dim2 ~ deregulation + position + ingovt + north + east, data = EP7_Parties)

###Model 5: civlib_laworder
EP7_model5_dim1 <- lm(party_oc_dim1 ~ civlib_laworder + position + ingovt + north + east, data = EP7_Parties)
EP7_model5_dim2 <- lm(party_oc_dim2 ~ civlib_laworder + position + ingovt + north + east, data = EP7_Parties)

###Model 6: deregulation + civlib_laworder 
EP7_model6_dim1 <- lm(party_oc_dim1 ~ deregulation + civlib_laworder + position + ingovt + north + east, data = EP7_Parties)
EP7_model6_dim2 <- lm(party_oc_dim2 ~ deregulation + civlib_laworder + position + ingovt + north + east, data = EP7_Parties)


###Table 4
EP7_output <- stargazer(EP7_model1_dim1, EP7_model1_dim2, EP7_model2_dim1, EP7_model2_dim2, EP7_model3_dim1, EP7_model3_dim2, EP7_model4_dim1, EP7_model4_dim2, EP7_model5_dim1, EP7_model5_dim2, EP7_model6_dim1, EP7_model6_dim2,
                        type             = "html",
                        out = "T4.html", 
                        title            = "EP7 National Party Delegations (Internet Policy RCVs)",
                        covariate.labels = c("Economic Left-Right", "GAL-TAN", "Deregulation", "Civil Liberties-Law&Order", "EU Integration", "In National Government", "Northern MS", "Eastern MS"),
                        dep.var.caption  = "OC Score",
                        dep.var.labels   = c("Model1, Dim1", "Model1, Dim2", "Model2, Dim1", "Model2, Dim2", "Model3, Dim1", "Model3, Dim2", "Model4, Dim1", "Model4, Dim2", "Model5, Dim1", "Model5, Dim2", "Model6, Dim1", "Model6, Dim2"),
                        model.numbers    = FALSE)


######
#Figures 2 & 3: Cutting Line plots

##data preparation
source("util.R")

##Figure 2: ACTA

####Panel: ACTA I
plot(x1, x2,
    main = "EP7 ACTA I",
    xlab = "liberal / authoritarian",
    ylab="pro / anti EU",
    xlim=c(-1,1), ylim=c(-1,1), type="n")

arrows(xws34+N2W34, yws34-N1W34, xws34-N2W34, yws34+N1W34, length=0.0, lwd=2, col="grey")
arrows(xws35+N2W35, yws35-N1W35, xws35-N2W35, yws35+N1W35, length=0.0, lwd=2, col="grey")
arrows(xws36+N2W36, yws36-N1W36, xws36-N2W36, yws36+N1W36, length=0.0, lwd=2, col="grey")
arrows(xws37+N2W37, yws37-N1W37, xws37-N2W37, yws37+N1W37, length=0.0, lwd=2, col="black")
arrows(xws38+N2W38, yws38-N1W38, xws38-N2W38, yws38+N1W38, length=0.0, lwd=2, col="grey")
arrows(xws39+N2W39, yws39-N1W39, xws39-N2W39, yws39+N1W39, length=0.0, lwd=2, col="black")

points(x1[epg == "EPP"], x2[epg == "EPP"], pch="E", col="#0000CCFF", font=2)
points(x1[epg == "S&D"], x2[epg == "S&D"], pch="S", col="#FF0000FF", font=2)       
points(x1[epg == "G/EFA"], x2[epg == "G/EFA"], pch="G", col="#00FF00FF", font=2)    
points(x1[epg == "ECR"], x2[epg == "ECR"], pch="C", col="#9900CCFF", font=2)    
points(x1[epg == "ALDE"], x2[epg == "ALDE"], pch="A", col="#FF00CCFF", font=2)    
points(x1[epg == "EFDD"], x2[epg == "EFDD"], pch="F", col="#00FFFFFF", font=2)    
points(x1[epg == "na"], x2[epg == "na"], pch="I", col="#CCCCCCFF", font=2)
points(x1[epg == "EUL/NGL"], x2[epg == "EUL/NGL"], pch="L", col="#358000FF", font=2)


####Panel: ACTA II
plot(x1, x2,
    main = "EP7 ACTA II",
    xlab = "liberal / authoritarian",
    ylab="pro / anti EU",
    xlim=c(-1,1), ylim=c(-1,1), type="n")

arrows(xws70+N2W70, yws70-N1W70, xws70-N2W70, yws70+N1W70, length=0.0, lwd=2, col="grey")
arrows(xws71+N2W71, yws71-N1W71, xws71-N2W71, yws71+N1W71, length=0.0, lwd=2, col="grey")
arrows(xws72+N2W72, yws72-N1W72, xws72-N2W72, yws72+N1W72, length=0.0, lwd=2, col="grey")
arrows(xws73+N2W73, yws73-N1W73, xws73-N2W73, yws73+N1W73, length=0.0, lwd=2, col="grey")
arrows(xws74+N2W74, yws74-N1W74, xws74-N2W74, yws74+N1W74, length=0.0, lwd=2, col="grey")
arrows(xws75+N2W75, yws75-N1W75, xws75-N2W75, yws75+N1W75, length=0.0, lwd=2, col="grey")
arrows(xws76+N2W76, yws76-N1W76, xws76-N2W76, yws76+N1W76, length=0.0, lwd=2, col="grey")
arrows(xws77+N2W77, yws77-N1W77, xws77-N2W77, yws77+N1W77, length=0.0, lwd=2, col="grey")
arrows(xws78+N2W78, yws78-N1W78, xws78-N2W78, yws78+N1W78, length=0.0, lwd=2, col="grey")
arrows(xws79+N2W79, yws79-N1W79, xws79-N2W79, yws79+N1W79, length=0.0, lwd=2, col="grey")
arrows(xws80+N2W80, yws80-N1W80, xws80-N2W80, yws80+N1W80, length=0.0, lwd=2, col="grey")
arrows(xws81+N2W81, yws81-N1W81, xws81-N2W81, yws81+N1W81, length=0.0, lwd=2, col="grey")
arrows(xws82+N2W82, yws82-N1W82, xws82-N2W82, yws82+N1W82, length=0.0, lwd=2, col="grey")
arrows(xws83+N2W83, yws83-N1W83, xws83-N2W83, yws83+N1W83, length=0.0, lwd=2, col="grey")
arrows(xws84+N2W84, yws84-N1W84, xws84-N2W84, yws84+N1W84, length=0.0, lwd=2, col="grey")
arrows(xws85+N2W85, yws85-N1W85, xws85-N2W85, yws85+N1W85, length=0.0, lwd=2, col="grey")
arrows(xws86+N2W86, yws86-N1W86, xws86-N2W86, yws86+N1W86, length=0.0, lwd=2, col="grey")
arrows(xws87+N2W87, yws87-N1W87, xws87-N2W87, yws87+N1W87, length=0.0, lwd=2, col="grey")
arrows(xws88+N2W88, yws88-N1W88, xws88-N2W88, yws88+N1W88, length=0.0, lwd=2, col="grey")
arrows(xws89+N2W89, yws89-N1W89, xws89-N2W89, yws89+N1W89, length=0.0, lwd=2, col="grey")
arrows(xws90+N2W90, yws90-N1W90, xws90-N2W90, yws90+N1W90, length=0.0, lwd=2, col="grey")
arrows(xws91+N2W91, yws91-N1W91, xws91-N2W91, yws91+N1W91, length=0.0, lwd=2, col="grey")
arrows(xws92+N2W92, yws92-N1W92, xws92-N2W92, yws92+N1W92, length=0.0, lwd=2, col="grey")
arrows(xws93+N2W93, yws93-N1W93, xws93-N2W93, yws93+N1W93, length=0.0, lwd=2, col="grey")
arrows(xws94+N2W94, yws94-N1W94, xws94-N2W94, yws94+N1W94, length=0.0, lwd=2, col="grey")
arrows(xws95+N2W95, yws95-N1W95, xws95-N2W95, yws95+N1W95, length=0.0, lwd=2, col="grey")
arrows(xws96+N2W96, yws96-N1W96, xws96-N2W96, yws96+N1W96, length=0.0, lwd=2, col="grey")
arrows(xws97+N2W97, yws97-N1W97, xws97-N2W97, yws97+N1W97, length=0.0, lwd=2, col="grey")
arrows(xws98+N2W98, yws98-N1W98, xws98-N2W98, yws98+N1W98, length=0.0, lwd=2, col="grey")
arrows(xws99+N2W99, yws99-N1W99, xws99-N2W99, yws99+N1W99, length=0.0, lwd=2, col="grey")
arrows(xws100+N2W100, yws100-N1W100, xws100-N2W100, yws100+N1W100, length=0.0, lwd=2, col="grey")
arrows(xws101+N2W101, yws101-N1W101, xws101-N2W101, yws101+N1W101, length=0.0, lwd=2, col="grey")
arrows(xws102+N2W102, yws102-N1W102, xws102-N2W102, yws102+N1W102, length=0.0, lwd=2, col="grey")
arrows(xws103+N2W103, yws103-N1W103, xws103-N2W103, yws103+N1W103, length=0.0, lwd=2, col="grey")
arrows(xws104+N2W104, yws104-N1W104, xws104-N2W104, yws104+N1W104, length=0.0, lwd=2, col="grey")
arrows(xws105+N2W105, yws105-N1W105, xws105-N2W105, yws105+N1W105, length=0.0, lwd=2, col="grey")
arrows(xws106+N2W106, yws106-N1W106, xws106-N2W106, yws106+N1W106, length=0.0, lwd=2, col="grey")
arrows(xws107+N2W107, yws107-N1W107, xws107-N2W107, yws107+N1W107, length=0.0, lwd=2, col="grey")
arrows(xws108+N2W108, yws108-N1W108, xws108-N2W108, yws108+N1W108, length=0.0, lwd=2, col="grey")
arrows(xws109+N2W109, yws109-N1W109, xws109-N2W109, yws109+N1W109, length=0.0, lwd=2, col="grey")
arrows(xws110+N2W110, yws110-N1W110, xws110-N2W110, yws110+N1W110, length=0.0, lwd=2, col="grey")
arrows(xws111+N2W111, yws111-N1W111, xws111-N2W111, yws111+N1W111, length=0.0, lwd=2, col="grey")
arrows(xws112+N2W112, yws112-N1W112, xws112-N2W112, yws112+N1W112, length=0.0, lwd=2, col="black")
arrows(xws113+N2W113, yws113-N1W113, xws113-N2W113, yws113+N1W113, length=0.0, lwd=2, col="red")

points(x1[epg == "EPP"], x2[epg == "EPP"], pch="E", col="#0000CCFF", font=2)
points(x1[epg == "S&D"], x2[epg == "S&D"], pch="S", col="#FF0000FF", font=2)       
points(x1[epg == "G/EFA"], x2[epg == "G/EFA"], pch="G", col="#00FF00FF", font=2)    
points(x1[epg == "ECR"], x2[epg == "ECR"], pch="C", col="#9900CCFF", font=2)    
points(x1[epg == "ALDE"], x2[epg == "ALDE"], pch="A", col="#FF00CCFF", font=2)    
points(x1[epg == "EFDD"], x2[epg == "EFDD"], pch="F", col="#00FFFFFF", font=2)    
points(x1[epg == "na"], x2[epg == "na"], pch="I", col="#CCCCCCFF", font=2)
points(x1[epg == "EUL/NGL"], x2[epg == "EUL/NGL"], pch="L", col="#358000FF", font=2)

####Panel: ACTA III
plot(x1, x2,
    main = "EP7 ACTA III",
    xlab = "liberal / authoritarian",
    ylab="pro / anti EU",
    xlim=c(-1,1), ylim=c(-1,1), type="n")

arrows(xws136+N2W136, yws136-N1W136, xws136-N2W136, yws136+N1W136, length=0.0, lwd=2, col="grey")
arrows(xws137+N2W137, yws137-N1W137, xws137-N2W137, yws137+N1W137, length=0.0, lwd=2, col="black")

points(x1[epg == "EPP"], x2[epg == "EPP"], pch="E", col="#0000CCFF", font=2)
points(x1[epg == "S&D"], x2[epg == "S&D"], pch="S", col="#FF0000FF", font=2)       
points(x1[epg == "G/EFA"], x2[epg == "G/EFA"], pch="G", col="#00FF00FF", font=2)    
points(x1[epg == "ECR"], x2[epg == "ECR"], pch="C", col="#9900CCFF", font=2)    
points(x1[epg == "ALDE"], x2[epg == "ALDE"], pch="A", col="#FF00CCFF", font=2)    
points(x1[epg == "EFDD"], x2[epg == "EFDD"], pch="F", col="#00FFFFFF", font=2)    
points(x1[epg == "na"], x2[epg == "na"], pch="I", col="#CCCCCCFF", font=2)
points(x1[epg == "EUL/NGL"], x2[epg == "EUL/NGL"], pch="L", col="#358000FF", font=2)


###Figure 3: Single Market in Electronic Communications
plot(x1, x2,
     main = "EP7 Electronic Communication",
     xlab = "liberal / authoritarian",
     ylab="pro / anti EU",
     xlim=c(-1,1), ylim=c(-1,1), type="n")

arrows(xws259+N2W259, yws259-N1W259, xws259-N2W259, yws259+N1W259, length=0.0, lwd=2, col="grey")
arrows(xws260+N2W260, yws260-N1W260, xws260-N2W260, yws260+N1W260, length=0.0, lwd=2, col="grey")
arrows(xws261+N2W261, yws261-N1W261, xws261-N2W261, yws261+N1W261, length=0.0, lwd=2, col="grey")
arrows(xws262+N2W262, yws262-N1W262, xws262-N2W262, yws262+N1W262, length=0.0, lwd=2, col="grey")
arrows(xws263+N2W263, yws263-N1W263, xws263-N2W263, yws263+N1W263, length=0.0, lwd=2, col="grey")
arrows(xws264+N2W264, yws264-N1W264, xws264-N2W264, yws264+N1W264, length=0.0, lwd=2, col="grey")
arrows(xws265+N2W265, yws265-N1W265, xws265-N2W265, yws265+N1W265, length=0.0, lwd=2, col="grey")
arrows(xws266+N2W266, yws266-N1W266, xws266-N2W266, yws266+N1W266, length=0.0, lwd=2, col="grey")
arrows(xws267+N2W267, yws267-N1W267, xws267-N2W267, yws267+N1W267, length=0.0, lwd=2, col="grey")

points(x1[epg == "EPP"], x2[epg == "EPP"], pch="E", col="#0000CCFF", font=2)
points(x1[epg == "S&D"], x2[epg == "S&D"], pch="S", col="#FF0000FF", font=2)       
points(x1[epg == "G/EFA"], x2[epg == "G/EFA"], pch="G", col="#00FF00FF", font=2)    
points(x1[epg == "ECR"], x2[epg == "ECR"], pch="C", col="#9900CCFF", font=2)    
points(x1[epg == "ALDE"], x2[epg == "ALDE"], pch="A", col="#FF00CCFF", font=2)    
points(x1[epg == "EFDD"], x2[epg == "EFDD"], pch="F", col="#00FFFFFF", font=2)    
points(x1[epg == "na"], x2[epg == "na"], pch="I", col="#CCCCCCFF", font=2)
points(x1[epg == "EUL/NGL"], x2[epg == "EUL/NGL"], pch="L", col="#358000FF", font=2)



######
#Appendix

##A3. Vector inflation models
car::vif(EP5_model3_dim1)

car::vif(EP6_model3_dim1)
car::vif(EP6_model6_dim1)

car::vif(EP7_model3_dim1)
car::vif(EP7_model6_dim1)


##A4. OC scree Trees
plot.OCskree(oc_EP5)
plot.OCskree(oc_EP6)
plot.OCskree(oc_EP7)


##A5. Robustness: OC Ideal Points with the French Communists as an Anchor
set.seed(789)

###EP5
oc_EP5_leftpolarity <- oc(RCV_EP5, polarity = c("BOUDJENAH Yasmine", "BOUDJENAH Yasmine"))

EP5_MEPs$oc_leftpolarity_dim1 <- oc_EP5_leftpolarity$legislators$coord1D
EP5_MEPs$oc_leftpolarity_dim2 <- oc_EP5_leftpolarity$legislators$coord2D

EP5_oc_leftpolarity_plot <- ggplot(EP5_MEPs, aes(x=oc_leftpolarity_dim1, y=oc_leftpolarity_dim2)) +
  geom_point(aes(color = epg, shape=epg),
             size= 3) +
  scale_color_manual(values = c("ELDR" = "#FF00CCFF", "EDD" = "#00FFFFFF", "EPP" = "#0000CCFF", "EUL/NGL" = "#358000FF", "G/EFA" = "#00FF00FF", "PSE" = "#FF0000FF", "UEN" = "#FF9900FF","na"="#CCCCCCFF")) +
  scale_shape_manual(values = c("ELDR" = "A", "EDD" = "F", "EPP" = "E", "EUL/NGL" = "L", "G/EFA" = "G", "PSE" = "S", "UEN" = "N", "na"="I")) +
  coord_fixed() +
  xlab('liberal / authoritarian') +
  ylab('pro / anti EU') +
  xlim(-1, 1) +
  ylim(-1, 1) +
  labs(title = 'EP5 Internet Policy')

EP5_oc_leftpolarity_plot

EP5_Parties_leftpolarity <- EP5_MEPs %>% group_by(ches_id) %>% 
  dplyr::summarize_at(vars(oc_leftpolarity_dim1, oc_leftpolarity_dim2), mean, na.rm=TRUE)

EP5_Parties_leftpolarity <- EP5_Parties_leftpolarity %>% drop_na(ches_id) %>% 
  rename(party_oc_leftpolarity_dim1=oc_leftpolarity_dim1) %>% 
  rename(party_oc_leftpolarity_dim2=oc_leftpolarity_dim2)

EP5_MEPs <- EP5_MEPs %>% full_join(EP5_Parties_leftpolarity, by="ches_id")

EP5_oc_leftpolarity_party_plot <- ggplot(EP5_MEPs, aes(x=party_oc_leftpolarity_dim1, y=party_oc_leftpolarity_dim2)) +
  geom_point(aes(color = epg, shape = epg),
             size= 3) +
  scale_color_manual(values = c("ELDR" = "#FF00CCFF", "EDD" = "#00FFFFFF", "EPP" = "#0000CCFF", "EUL/NGL" = "#358000FF", "G/EFA" = "#00FF00FF", "PSE" = "#FF0000FF", "UEN" = "#FF9900FF","na"="#CCCCCCFF")) +
  scale_shape_manual(values = c("ELDR" = "A", "EDD" = "F", "EPP" = "E", "EUL/NGL" = "L", "G/EFA" = "G", "PSE" = "S", "UEN" = "N", "na"="I")) +
  coord_fixed() +
  xlab('liberal / authoritarian') +
  ylab('pro / anti EU') +
  xlim(-1, 1) +
  ylim(-1, 1) +
  labs(title = 'EP5 Internet Policy (National Parties)')

EP5_oc_leftpolarity_party_plot


###EP6
RCV_EP6 <- rollcall(data=EP6_RCV_Internet_MEP[,9:ncol(EP6_RCV_Internet_MEP)], 
                    yea=1, 
                    nay=2, 
                    missing=c(0,3,4), 
                    notInLegis=5, 
                    legis.names = EP6_RCV_Internet_MEP$mep_id,
                    vote.names = colnames(EP6_RCV_Internet_MEP[,9:ncol(EP6_RCV_Internet_MEP)]),
                    legis.data = EP6_RCV_Internet_MEP[,1:8],
                    vote.data = NULL,
                    desc = NULL)

oc_EP6_leftpolarity <- oc(RCV_EP6, polarity = c(284, 284))

summary(oc_EP6)
plot(oc_EP6)

EP6_MEPs$oc_leftpolarity_dim1 <- oc_EP6_leftpolarity$legislators$coord1D
EP6_MEPs$oc_leftpolarity_dim2 <- oc_EP6_leftpolarity$legislators$coord2D

EP6_oc_leftpolarity_plot <- ggplot(EP6_MEPs, aes(x=oc_leftpolarity_dim1, y=oc_leftpolarity_dim2)) +
  geom_point(aes(color = epg_name, shape = epg_name),
             size= 3) +
  scale_color_manual(values = c("ALDE" = "#FF00CCFF", "IND/DEM" = "#00FFFFFF", "EPP-ED" = "#0000CCFF", "EUL/NGL" = "#358000FF", "G/EFA" = "#00FF00FF", "SOC" = "#FF0000FF", "UEN" = "#FF9900FF","na"="#CCCCCCFF")) +
  scale_shape_manual(values = c("ALDE" = "A", "IND/DEM" = "F", "EPP-ED" = "E", "EUL/NGL" = "L", "G/EFA" = "G", "SOC" = "S", "UEN" = "N", "na"="I")) +
  coord_fixed() +
  xlab('liberal / authoritarian') +
  ylab('pro / anti EU') +
  xlim(-1, 1) +
  ylim(-1, 1) +
  labs(title = 'EP6 Internet Policy')

EP6_oc_leftpolarity_plot

EP6_Parties_leftpolarity <- EP6_MEPs %>% group_by(ches_id) %>% 
  dplyr::summarize_at(vars(oc_leftpolarity_dim1, oc_leftpolarity_dim2), mean, na.rm=TRUE)
EP6_Parties_leftpolarity <- EP6_Parties_leftpolarity %>% drop_na(ches_id) %>% 
  rename(party_oc_leftpolarity_dim1=oc_leftpolarity_dim1) %>% 
  rename(party_oc_leftpolarity_dim2=oc_leftpolarity_dim2) 

EP6_MEPs <- EP6_MEPs %>% full_join(EP6_Parties_leftpolarity, by="ches_id")

EP6_oc_leftpolarity_party_plot <- ggplot(EP6_MEPs, aes(x=party_oc_leftpolarity_dim1, y=party_oc_leftpolarity_dim2)) +
  geom_point(aes(color = epg_name, shape = epg_name),
             size= 3) +
  scale_color_manual(values = c("ALDE" = "#FF00CCFF", "IND/DEM" = "#00FFFFFF", "EPP-ED" = "#0000CCFF", "EUL/NGL" = "#358000FF", "G/EFA" = "#00FF00FF", "SOC" = "#FF0000FF", "UEN" = "#FF9900FF","na"="#CCCCCCFF")) +
  scale_shape_manual(values = c("ALDE" = "A", "IND/DEM" = "F", "EPP-ED" = "E", "EUL/NGL" = "L", "G/EFA" = "G", "SOC" = "S", "UEN" = "N", "na"="I")) +
  coord_fixed() +
  xlab('liberal / authoritarian') +
  ylab('pro / anti EU') +
  xlim(-1, 1) +
  ylim(-1, 1) +
  labs(title = 'EP6 Internet Policy (National Parties)')

EP6_oc_leftpolarity_party_plot


##EP7
RCV_EP7 <- rollcall(data=EP7_RCV_Internet[,6:ncol(EP7_RCV_Internet)], 
                    yea=1, 
                    nay=2, 
                    missing=c(3,4,5), 
                    notInLegis=0, 
                    legis.names = EP7_RCV_Internet$mep_id,
                    vote.names = colnames(EP7_RCV_Internet[,6:ncol(EP7_RCV_Internet)]),
                    legis.data = EP7_RCV_Internet[,1:5],
                    vote.data = NULL,
                    desc = NULL)

oc_EP7_leftpolarity <- oc(RCV_EP7, polarity = c(441, 441))

EP7_MEPs$oc_leftpolarity_dim1 <- oc_EP7_leftpolarity$legislators$coord1D
EP7_MEPs$oc_leftpolarity_dim2 <- oc_EP7_leftpolarity$legislators$coord2D

EP7_oc_leftpolarity_plot <- ggplot(EP7_MEPs, aes(x=oc_leftpolarity_dim1, y=oc_leftpolarity_dim2)) +
  geom_point(aes(color = epg, shape = epg),
             size= 3) +
  scale_color_manual(values = c("ALDE" = "#FF00CCFF", "ECR" = "#9900CCFF", "EFDD" = "#00FFFFFF", "EPP" = "#0000CCFF", "EUL/NGL" = "#358000FF", "G/EFA" = "#00FF00FF", "S&D" = "#FF0000FF", "na"="#CCCCCCFF")) +
  scale_shape_manual(values = c("ALDE" = "A", "ECR" = "C", "EFDD" = "F", "EPP" = "E", "EUL/NGL" = "L", "G/EFA" = "G", "S&D" = "S", "na"="I")) +
  coord_fixed() +
  xlab('liberal / authoritarian') +
  ylab('pro / anti EU') +
  xlim(-1, 1) +
  ylim(-1, 1) +
  labs(title = 'EP7 Internet Policy')

EP7_oc_leftpolarity_plot

EP7_Parties_leftpolarity <- EP7_MEPs %>% group_by(ches_id) %>% dplyr::summarize_at(vars(oc_leftpolarity_dim1, oc_leftpolarity_dim2), mean, na.rm=TRUE)
EP7_Parties_leftpolarity <- EP7_Parties_leftpolarity %>% drop_na(ches_id) %>% 
  rename(party_oc_leftpolarity_dim1=oc_leftpolarity_dim1) %>% 
  rename(party_oc_leftpolarity_dim2=oc_leftpolarity_dim2)

EP7_MEPs <- EP7_MEPs %>% full_join(EP7_Parties_leftpolarity, by="ches_id")


EP7_oc_leftpolarity_party_plot <- ggplot(EP7_MEPs, aes(x=party_oc_leftpolarity_dim1, y=party_oc_leftpolarity_dim2)) +
  geom_point(aes(color = epg, shape = epg),
             size= 3) +
  scale_color_manual(values = c("ALDE" = "#FF00CCFF", "ECR" = "#9900CCFF", "EFDD" = "#00FFFFFF", "EPP" = "#0000CCFF", "EUL/NGL" = "#358000FF", "G/EFA" = "#00FF00FF", "S&D" = "#FF0000FF", "na"="#CCCCCCFF")) +
  scale_shape_manual(values = c("ALDE" = "A", "ECR" = "C", "EFDD" = "F", "EPP" = "E", "EUL/NGL" = "L", "G/EFA" = "G", "S&D" = "S", "na"="I")) +
  coord_fixed() +
  xlab('liberal / authoritarian') +
  ylab('pro / anti EU') +
  xlim(-1, 1) +
  ylim(-1, 1) +
  labs(title = 'EP7 Internet Policy (National Parties)')
EP7_oc_leftpolarity_party_plot


###Figure A2
FA2 <- EP5_oc_leftpolarity_plot + EP6_oc_leftpolarity_plot + EP7_oc_leftpolarity_plot + 
  EP5_oc_leftpolarity_party_plot+ EP6_oc_leftpolarity_party_plot + EP7_oc_leftpolarity_party_plot +
  plot_layout(ncol=3)

ggsave("FA2.jpeg", F1, width = 33.1, height = 16.1, units = "cm", dpi = 300)


##A6. Robustness: W-NOMINATE Regressions

###EP5
wnominate_EP5 <- wnominate(RCV_EP5, polarity = c("BORGHEZIO Mario", "BORGHEZIO Mario"))

EP5_MEPs$nominate_internet_dim1 <- wnominate_EP5$legislators$coord1D
EP5_MEPs$nominate_internet_dim2 <- wnominate_EP5$legislators$coord2D

EP5_Parties <- EP5_MEPs %>% group_by(ches_id) %>% dplyr::summarize_at(vars(nominate_internet_dim1, nominate_internet_dim2), mean, na.rm=TRUE)
EP5_Parties <- EP5_Parties %>% drop_na(ches_id) %>% 
  rename(party_internet_dim1=nominate_internet_dim1) %>% 
  rename(party_internet_dim2=nominate_internet_dim2)

EP5_MEPs <- EP5_MEPs %>% full_join(EP5_Parties, by="ches_id")

EP5_Parties <- EP5_MEPs %>% 
  dplyr::select(party_short, ches_id, member_state, epg, lrecon, galtan, position, govt, 
                28:ncol(EP5_MEPs)) %>% 
  group_by(party_short, ches_id, epg) %>% 
  summarise_each(funs(first(.)))

EP5_Parties <- EP5_Parties %>% 
  mutate(ingovt = case_when((govt == "in government") ~ as.numeric(1), TRUE ~ as.numeric(0))) %>%
  mutate(region = case_when(member_state == "A" ~ "north", 
                            member_state == "B" ~ "north",
                            member_state == "K" ~ "north", 
                            member_state == "O" ~ "north", 
                            member_state == "D" ~ "north", 
                            member_state == "R" ~ "north", 
                            member_state == "L" ~ "north", 
                            member_state == "N" ~ "north", 
                            member_state == "S" ~ "north", 
                            member_state == "U" ~ "north", 
                            TRUE ~ member_state)) %>% 
  mutate(region = case_when(member_state == "F" ~ "south",
                            member_state == "G" ~ "south", 
                            member_state == "I" ~  "south", 
                            member_state == "M" ~  "south", 
                            member_state == "P" ~ "south", 
                            member_state == "E" ~ "south", 
                            TRUE ~ region)) %>% 
  mutate(north = case_when(region == "north" ~ as.numeric(1), TRUE ~ as.numeric(0))) %>% 
  mutate(south = case_when(region == "south" ~ as.numeric(1), TRUE ~ as.numeric(0))) 

EP5_Parties <- EP5_Parties %>% drop_na()

###Model1: lrecon
EP5_nominate_model1_dim1 <- lm(party_internet_dim1 ~ lrecon + position + ingovt + north, data = EP5_Parties)
EP5_nominate_model1_dim2 <- lm(party_internet_dim2 ~ lrecon + position + ingovt + north, data = EP5_Parties)

###Model2: galtan
EP5_nominate_model2_dim1 <- lm(party_internet_dim1 ~ galtan + position + ingovt + north, data = EP5_Parties)
EP5_nominate_model2_dim2 <- lm(party_internet_dim2 ~ galtan + position + ingovt + north, data = EP5_Parties)

###Model3: lrecon + galtan
EP5_nominate_model3_dim1 <- lm(party_internet_dim1 ~ lrecon + galtan + position + ingovt + north, data = EP5_Parties)
EP5_nominate_model3_dim2 <- lm(party_internet_dim2 ~ lrecon + galtan + position + ingovt + north, data = EP5_Parties)

###Table A4
EP5_nominate_output <- stargazer(EP5_nominate_model1_dim1, EP5_nominate_model1_dim2, EP5_nominate_model2_dim1, EP5_nominate_model2_dim2, EP5_nominate_model3_dim1, EP5_nominate_model3_dim2,
                                 type             = "html",
                                 out = "TA4.html", 
                                 title            = "EP5 National Party Delegations (Internet Policy RCVs)",
                                 covariate.labels = c("Economic Left-Right", "GAL-TAN", "EU Integration", "In National Government", "Northern MS"),
                                 dep.var.caption  = "W-Nominate Score",
                                 dep.var.labels   = c("Model1, Dim1", "Model1, Dim2", "Model2, Dim1", " Model2, Dim2", "Model3, Dim1", " Model3, Dim2"),
                                 model.numbers    = FALSE)


##EP6
wnominate_EP6 <- wnominate(RCV_EP6, polarity = c(625, 625))

EP6_MEPs$nominate_internet_dim1 <- wnominate_EP6$legislators$coord1D
EP6_MEPs$nominate_internet_dim2 <- wnominate_EP6$legislators$coord2D

EP6_Parties <- EP6_MEPs %>% group_by(ches_id) %>% 
  dplyr::summarize_at(vars(nominate_internet_dim1, nominate_internet_dim2), mean, na.rm=TRUE)
EP6_Parties <- EP6_Parties %>% drop_na(ches_id) %>% 
  rename(party_internet_dim1=nominate_internet_dim1) %>% 
  rename(party_internet_dim2=nominate_internet_dim2)

EP6_MEPs <- EP6_MEPs %>% full_join(EP6_Parties, by="ches_id")

EP6_Parties <- EP6_MEPs %>% 
  dplyr::select(party_short, ches_id, country_name, epg_name, lrecon, galtan, position, deregulation, civlib_laworder, civlib_salience, govt, 
                27:ncol(EP6_MEPs)) %>% 
  group_by(party_short, ches_id, country_name, epg_name) %>% 
  summarise_each(funs(first(.)))

EP6_Parties <- EP6_Parties %>% 
  mutate(ingovt = case_when((govt == "in government") ~ as.numeric(1), TRUE ~ as.numeric(0))) %>%
  mutate(region = case_when(country_name == "Austria" ~ "north", 
                            country_name == "Belgium" ~ "north",
                            country_name == "Denmark" ~ "north", 
                            country_name == "Finland" ~ "north", 
                            country_name == "Germany" ~ "north", 
                            country_name == "Ireland" ~ "north", 
                            country_name == "Luxemburg" ~ "north", 
                            country_name == "Netherlands" ~ "north", 
                            country_name == "Sweden" ~ "north", 
                            country_name == "UK" ~ "north", 
                            TRUE ~ country_name)) %>% 
  mutate(region = case_when(country_name == "Cyprus" ~ "south", 
                            country_name == "France" ~ "south",
                            country_name == "Greece" ~ "south", 
                            country_name == "Italy" ~  "south", 
                            country_name == "Malta" ~  "south", 
                            country_name == "Portugal" ~ "south", 
                            country_name == "Spain" ~ "south", 
                            TRUE ~ region)) %>% 
  mutate(region = case_when(country_name == "Bulgaria"       ~ "east", 
                            country_name == "Czech Republic" ~ "east",
                            country_name == "Estonia"        ~ "east", 
                            country_name == "Hungary"        ~ "east", 
                            country_name == "Latvia"         ~ "east", 
                            country_name == "Lithuania"      ~ "east", 
                            country_name == "Poland"         ~ "east", 
                            country_name == "Romania"        ~ "east", 
                            country_name == "Slovakia"       ~ "east", 
                            country_name == "Slovenia"       ~ "east", 
                            TRUE ~ region)) %>% 
  mutate(north = case_when(region == "north" ~ as.numeric(1), TRUE ~ as.numeric(0))) %>% 
  mutate(south = case_when(region == "south" ~ as.numeric(1), TRUE ~ as.numeric(0))) %>% 
  mutate(east = case_when(region == "east" ~ as.numeric(1), TRUE ~ as.numeric(0))) 

EP6_Parties <- EP6_Parties %>% drop_na()

###Model1: lrecon
EP6_nominate_model1_dim1 <- lm(party_internet_dim1 ~ lrecon + position + ingovt + north + east, data = EP6_Parties)
EP6_nominate_model1_dim2 <- lm(party_internet_dim2 ~ lrecon + position + ingovt + north + east, data = EP6_Parties)

###Model2: galtan
EP6_nominate_model2_dim1 <- lm(party_internet_dim1 ~ galtan + position + ingovt + north + east, data = EP6_Parties)
EP6_nominate_model2_dim2 <- lm(party_internet_dim2 ~ galtan + position + ingovt + north + east, data = EP6_Parties)

###Model3: lrecon + galtan
EP6_nominate_model3_dim1 <- lm(party_internet_dim1 ~ lrecon + galtan + position + ingovt + north + east, data = EP6_Parties)
EP6_nominate_model3_dim2 <- lm(party_internet_dim2 ~ lrecon + galtan + position + ingovt + north + east, data = EP6_Parties)

###Model 4: deregulation 
EP6_nominate_model4_dim1 <- lm(party_internet_dim1 ~ deregulation + position + ingovt + north + east, data = EP6_Parties)
EP6_nominate_model4_dim2 <- lm(party_internet_dim2 ~ deregulation + position + ingovt + north + east, data = EP6_Parties)

###Model 5: civlib_laworder
EP6_nominate_model5_dim1 <- lm(party_internet_dim1 ~ civlib_laworder + position + ingovt + north  + east, data = EP6_Parties)
EP6_nominate_model5_dim2 <- lm(party_internet_dim2 ~ civlib_laworder + position + ingovt + north  + east, data = EP6_Parties)

###Model 6: deregulation + civlib_laworder
EP6_nominate_model6_dim1 <- lm(party_internet_dim1 ~ deregulation + civlib_laworder + position + ingovt + north + east, data = EP6_Parties)
EP6_nominate_model6_dim2 <- lm(party_internet_dim2 ~ deregulation + civlib_laworder + position + ingovt + north + east, data = EP6_Parties)

###Table A5
EP6_nominate_output <- stargazer(EP6_nominate_model1_dim1, EP6_nominate_model1_dim2, EP6_nominate_model2_dim1, EP6_nominate_model2_dim2, EP6_nominate_model3_dim1, EP6_nominate_model3_dim2, EP6_nominate_model4_dim1, EP6_nominate_model4_dim2, EP6_nominate_model5_dim1, EP6_nominate_model5_dim2, EP6_nominate_model6_dim1, EP6_nominate_model6_dim2,
                                 type             = "html",
                                 out = "TA5.html", 
                                 title            = "EP6 National Party Delegations (Internet Policy RCVs)",
                                 covariate.labels = c("Economic Left-Right", "GAL-TAN", "Deregulation", "Civil Liberties-Law&Order", "EU Integration", "In National Government", "Northern MS", "Eastern MS"),
                                 dep.var.caption  = "W-Nominate Score",
                                 dep.var.labels   = c("Model1, Dim1", "Model1, Dim2", "Model2, Dim1", "Model2, Dim2", "Model3, Dim1", "Model3, Dim2", "Model4, Dim1", "Model4, Dim2", "Model5, Dim1", "Model5, Dim2", "Model6, Dim1", "Model6, Dim2"),
                                 model.numbers    = FALSE)


##EP7
wnominate_EP7 <- wnominate(RCV_EP7, polarity = c(72, 72))

EP7_MEPs$nominate_internet_dim1 <- wnominate_EP7$legislators$coord1D
EP7_MEPs$nominate_internet_dim2 <- wnominate_EP7$legislators$coord2D

EP7_Parties <- EP7_MEPs %>% group_by(ches_id) %>% dplyr::summarize_at(vars(nominate_internet_dim1, nominate_internet_dim2), mean, na.rm=TRUE)
EP7_Parties <- EP7_Parties %>% drop_na(ches_id) %>% 
  rename(party_internet_dim1=nominate_internet_dim1) %>% 
  rename(party_internet_dim2=nominate_internet_dim2)

EP7_MEPs <- EP7_MEPs %>% full_join(EP7_Parties, by="ches_id")

EP7_Parties <- EP7_MEPs %>% 
  dplyr::select(party_short, ches_id, country, epg, lrecon, galtan, position, deregulation, civlib_laworder, civlib_salience, govt, 
                27:ncol(EP7_MEPs)) %>% 
  group_by(party_short, ches_id, epg) %>% 
  summarise_each(funs(first(.)))

EP7_Parties <- EP7_Parties %>% 
  mutate(ingovt = case_when((govt == "in government") ~ as.numeric(1), TRUE ~ as.numeric(0))) %>% 
  mutate(region = case_when(country == "Austria" ~ "north", 
                            country == "Belgium" ~ "north",
                            country == "Denmark" ~ "north", 
                            country == "Finland" ~ "north", 
                            country == "Germany" ~ "north", 
                            country == "Ireland" ~ "north", 
                            country == "Luxembourg" ~ "north", 
                            country == "Netherlands" ~ "north", 
                            country == "Sweden" ~ "north", 
                            country == "United Kingdom" ~ "north", 
                            TRUE ~ country)) %>% 
  mutate(region = case_when(country == "Cyprus" ~ "south", 
                            country == "France" ~ "south",
                            country == "Greece" ~ "south", 
                            country == "Italy" ~  "south", 
                            country == "Malta" ~  "south", 
                            country == "Portugal" ~ "south", 
                            country == "Spain" ~ "south", 
                            TRUE ~ region)) %>% 
  mutate(region = case_when(country == "Bulgaria"       ~ "east",
                            country == "Croatia"       ~ "east",
                            country == "Czech Republic" ~ "east",
                            country == "Estonia"        ~ "east", 
                            country == "Hungary"        ~ "east", 
                            country == "Latvia"         ~ "east", 
                            country == "Lithuania"      ~ "east", 
                            country == "Poland"         ~ "east", 
                            country == "Romania"        ~ "east", 
                            country == "Slovakia"       ~ "east", 
                            country == "Slovenia"       ~ "east", 
                            TRUE ~ region)) %>% 
  mutate(north = case_when(region == "north" ~ as.numeric(1), TRUE ~ as.numeric(0))) %>% 
  mutate(south = case_when(region == "south" ~ as.numeric(1), TRUE ~ as.numeric(0))) %>% 
  mutate(east = case_when(region == "east" ~ as.numeric(1), TRUE ~ as.numeric(0)))

EP7_Parties <- EP7_Parties %>% drop_na()

###Model1: lrecon
EP7_nominate_model1_dim1 <- lm(party_internet_dim1 ~ lrecon + position + ingovt + north + east, data = EP7_Parties)
EP7_nominate_model1_dim2 <- lm(party_internet_dim2 ~ lrecon + position + ingovt + north + east, data = EP7_Parties)

###Model2: galtan
EP7_nominate_model2_dim1 <- lm(party_internet_dim1 ~ galtan + position + ingovt + north + east, data = EP7_Parties)
EP7_nominate_model2_dim2 <- lm(party_internet_dim2 ~ galtan + position + ingovt + north + east, data = EP7_Parties)


###Model3: lrecon + galtan
EP7_nominate_model3_dim1 <- lm(party_internet_dim1 ~ lrecon + galtan + position + ingovt + north + east, data = EP7_Parties)
EP7_nominate_model3_dim2 <- lm(party_internet_dim2 ~ lrecon + galtan + position + ingovt + north + east, data = EP7_Parties)

###Model 4: deregulation 
EP7_nominate_model4_dim1 <- lm(party_internet_dim1 ~ deregulation + position + ingovt + north + east, data = EP7_Parties)
EP7_nominate_model4_dim2 <- lm(party_internet_dim2 ~ deregulation + position + ingovt + north + east, data = EP7_Parties)

###Model 5: civlib_laworder
EP7_nominate_model5_dim1 <- lm(party_internet_dim1 ~ civlib_laworder + position + ingovt + north + east, data = EP7_Parties)
EP7_nominate_model5_dim2 <- lm(party_internet_dim2 ~ civlib_laworder + position + ingovt + north + east, data = EP7_Parties)

###Model 6: deregulation + ciinternetib_laworder 
EP7_nominate_model6_dim1 <- lm(party_internet_dim1 ~ deregulation + civlib_laworder + position + ingovt + north + east, data = EP7_Parties)
EP7_nominate_model6_dim2 <- lm(party_internet_dim2 ~ deregulation + civlib_laworder + position + ingovt + north + east, data = EP7_Parties)

###Table A6
EP7_nominate <- stargazer(EP7_nominate_model1_dim1, EP7_nominate_model1_dim2, EP7_nominate_model2_dim1, EP7_nominate_model2_dim2, EP7_nominate_model3_dim1, EP7_nominate_model3_dim2, EP7_nominate_model4_dim1, EP7_nominate_model4_dim2, EP7_nominate_model5_dim1, EP7_nominate_model5_dim2, EP7_nominate_model6_dim1, EP7_nominate_model6_dim2,
                          type             = "html",
                          out = "TA6.html", 
                          title            = "EP7 National Party Delegations (Internet Policy RCVs)",
                          covariate.labels = c("Economic Left-Right", "GAL-TAN", "Deregulation", "Civil Liberties-Law&Order", "EU Integration", "In National Government", "Northern MS", "Eastern MS"),
                          dep.var.caption  = "W-Nominate Score",
                          dep.var.labels   = c("Model1, Dim1", "Model1, Dim2", "Model2, Dim1", "Model2, Dim2", "Model3, Dim1", "Model3, Dim2", "Model4, Dim1", "Model4, Dim2", "Model5, Dim1", "Model5, Dim2", "Model6, Dim1", "Model6, Dim2"),
                          model.numbers    = FALSE)